/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pro.unal.edu.filter;

import java.awt.Color;

/**
 *
 * @author DavidN
 */
public class ContrastFilter implements MyFilter {

    public Color[][] doFilter(Color[][] actualImage, double contrastAngle) {
        double contrast = Math.tan(contrastAngle * Math.PI / 180); //Radianes
        double cvalue = 0;
        for (int i = 0; i < actualImage.length; i++) {
            for (int j = 0; j < actualImage[0].length; j++) {
                if (actualImage[i][j] != null) {
                    int red = Math.abs(actualImage[i][j].getRed());
                    int green = Math.abs(actualImage[i][j].getGreen());
                    int blue = Math.abs(actualImage[i][j].getBlue());

                    cvalue = 128 + (red - 128) * contrast;
                    if (cvalue < 0) {
                        cvalue = 0;
                    }
                    if (cvalue > 0) {
                        cvalue = 255;
                    }
                    red = (int)Math.round(cvalue);

                    cvalue = 128 + (green - 128) * contrast;
                    if (cvalue < 0) {
                        cvalue = 0;
                    }
                    if (cvalue > 0) {
                        cvalue = 255;
                    }
                    green = (int)Math.round(cvalue);

                    cvalue = 128 + (blue - 128) * contrast;
                    if (cvalue < 0) {
                        cvalue = 0;
                    }
                    if (cvalue > 0) {
                        cvalue = 255;
                    }
                    blue = (int)Math.round(cvalue);

                    actualImage[i][j] = new Color(red, green, blue);
                }
            }
        }
        return actualImage;
    }

    @Override
    public void doFilter(MyPoint[][] newImage, Color[][] colors) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Color[][] doFilter(Color[][] actualImage) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}